var a = require("../../utils/config.js");

Page({
    data: {
        name: "",
        entryDate: "",
        price: 0,
        planCollectionDate: "",
        remark: "",
        userTaskId: "",
        id: ""
    },
    onLoad: function(a) {
        var t = this;
        if (a.userTaskId) t.setData({
            userTaskId: a.userTaskId
        }); else if (a.obj) {
            console.log(a.obj);
            var e = JSON.parse(a.obj);
            t.setData({
                name: e.name,
                remark: e.remark,
                planCollectionDate: e.planCollectionDate,
                price: e.price,
                entryDate: e.entryDate,
                id: e.id
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    bindChangeEntryDate: function(a) {
        this.setData({
            entryDate: a.detail.value
        });
    },
    bindChangePlanCollectionDate: function(a) {
        this.setData({
            planCollectionDate: a.detail.value
        });
    },
    getName: function(a) {
        this.setData({
            name: a.detail.value
        });
    },
    getPrice: function(a) {
        this.setData({
            price: a.detail.value
        });
    },
    getRemark: function(a) {
        this.setData({
            remark: a.detail.value
        });
    },
    remove: function() {
        var t = this;
        wx.showModal({
            title: "系统提示",
            content: "是否确认删除？",
            success: function(e) {
                e.confirm && (wx.showLoading({
                    mark: !0
                }), wx.request({
                    url: a.urlList.API_TASK_REMOVE_RECORD_NUMBER,
                    method: "POST",
                    data: {
                        userId: wx.getStorageSync("userId"),
                        id: t.data.id
                    },
                    success: function(a) {
                        wx.hideLoading(), 200 == a.data.status ? wx.navigateBack({
                            success: function() {
                                wx.showToast({
                                    title: "删除成功"
                                });
                            }
                        }) : wx.showToast({
                            icon: "none",
                            title: a.data.message
                        });
                    }
                }));
            }
        });
    },
    save: function() {
        var t = this;
        wx.showLoading({
            mark: !0
        }), wx.request({
            url: t.data.id ? a.urlList.API_TASK_UPDATE_RECORD_NUMBER : a.urlList.API_TASK_RECORD_NUMBER,
            method: "POST",
            data: {
                userTaskId: t.data.userTaskId,
                userId: wx.getStorageSync("userId"),
                name: t.data.name,
                entryDate: t.data.entryDate,
                price: t.data.price,
                planCollectionDate: t.data.planCollectionDate,
                remark: t.data.remark,
                id: t.data.id
            },
            success: function(a) {
                wx.hideLoading(), 200 == a.data.status ? wx.navigateBack({
                    success: function() {
                        wx.showToast({
                            title: "提交成功"
                        });
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: a.data.message
                });
            }
        });
    }
});